<template>
  <div class="app-container">
    <!-- 顶部控制台 -->
    <div class="filter-container">
      <el-select class="filter-item" style="width: 160px" size="mini" v-model="form.searchSource" @change="handlePageInit">
        <el-option v-for="item in pageData.searchSourceList" :key="item.value" :label="item.label" :value="item.value"/>
      </el-select>
      <el-select class="filter-item" style="width: 160px" size="mini" v-model="form.searchPlate" @change="handlePageInit">
        <el-option v-for="item in pageData.searchPlateList" :key="item.value" :label="item.label" :value="item.value"/>
      </el-select>
      <el-select class="filter-item" style="width: 160px" size="mini" v-model="form.searchPayType" @change="handlePageInit">
        <el-option v-for="item in pageData.searchPayTypeList" :key="item.value" :label="item.label" :value="item.value"/>
      </el-select>
      <el-select class="filter-item" style="width: 160px" size="mini" v-model="form.searchPayStatus" @change="handlePageInit">
        <el-option v-for="item in pageData.searchPayStatusList" :key="item.value" :label="item.label" :value="item.value"/>
      </el-select>
      <el-select class="filter-item" style="width: 160px" size="mini" v-model="form.searchInvoiceStatus" @change="handlePageInit">
        <el-option v-for="item in pageData.searchInvoiceStatusList" :key="item.value" :label="item.label" :value="item.value"/>
      </el-select>
      <el-select class="filter-item" style="width: 160px" size="mini" v-model="form.searchCommodityType" @change="handlePageInit">
        <el-option v-for="item in pageData.searchCommodityTypeList" :key="item.value" :label="item.label" :value="item.value"/>
      </el-select>
      <el-date-picker class="filter-item" size="mini" v-model="form.searchDate" type="daterange" :unlink-panels="pageData.unlinkPanels"
                      range-separator="至"
                      start-placeholder="开始日期"
                      end-placeholder="结束日期"
                      :picker-options="pageData.pickerOptions" @change="handlePageInit">
      </el-date-picker>
      <el-button type="primary" size="mini" icon="el-icon-share" @click="handleExportOrderButtonClick">订单导出</el-button>
      <el-button type="primary" size="mini" icon="el-icon-share" @click="handleExportOrderInvoiceButtonClick">发票导出</el-button>
    </div>
    <!-- 页面数据列表 -->
    <el-table :data="responseData.tableList"
              border style="width: 100%;"
              v-loading="pageData.loading"
              element-loading-text="拼命加载中"
              element-loading-spinner="el-icon-loading"
              element-loading-background="rgba(0, 0, 0, 0.8)"
              :header-cell-style="{ background: '#545C64', color: '#ffffff' }"
              @selection-change="handleTableSelection">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column fixed="left" prop="orderId" label="订单编号" width="240" align="center"/>
      <el-table-column prop="orderDescribe" label="订单描述" width="320" align="center"/>
      <el-table-column prop="cashFee" label="订单金额" width="120" align="center"/>
      <el-table-column prop="orderPayStatus" label="支付状态" width="120" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.orderPayStatus === -1"><el-tag type="info">已删除</el-tag></span>
          <span v-if="scope.row.orderPayStatus === 0"><el-tag type="warning">未支付</el-tag></span>
          <span v-if="scope.row.orderPayStatus === 1"><el-tag type="success">已支付</el-tag></span>
          <span v-if="scope.row.orderPayStatus === 2"><el-tag type="danger">订单超时</el-tag></span>
          <span v-if="scope.row.orderPayStatus === 3"><el-tag type="primary">部分支付</el-tag></span>
        </template>
      </el-table-column>
      <el-table-column prop="orderPayType" label="支付方式" width="120" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.orderPayType === 1"><el-tag type="success">微信支付</el-tag></span>
          <span v-if="scope.row.orderPayType === 2"><el-tag type="warning">支付宝支付</el-tag></span>
          <span v-if="scope.row.orderPayType === 3"><el-tag type="danger">转账汇款</el-tag></span>
          <span v-if="scope.row.orderPayType === 4"><el-tag type="info">余额支付</el-tag></span>
          <span v-if="scope.row.orderPayType === 5"><el-tag type="primary">IOS内购</el-tag></span>
          <span v-if="scope.row.orderPayType === 6"><el-tag type="success">微信扫码支付</el-tag></span>
          <span v-if="scope.row.orderPayType === 7"><el-tag type="warning">微信jsapi支付</el-tag></span>
          <span v-if="scope.row.orderPayType === 8"><el-tag type="danger">支付宝扫码支付</el-tag></span>
          <span v-if="scope.row.orderPayType === 10"><el-tag type="info">易考通ios微信</el-tag></span>
          <span v-if="scope.row.orderPayType === 11"><el-tag type="primary">易考通ios支付宝</el-tag></span>
        </template>
      </el-table-column>
      <el-table-column prop="orderPayPlatform" label="支付平台" width="140" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.orderPayPlatform === 1"><el-tag type="success">IOS</el-tag></span>
          <span v-if="scope.row.orderPayPlatform === 2"><el-tag type="warning">Android</el-tag></span>
          <span v-if="scope.row.orderPayPlatform === 3"><el-tag type="primary">PC</el-tag></span>
          <span v-if="scope.row.orderPayPlatform === 4"><el-tag type="info">微信</el-tag></span>
          <span v-if="scope.row.orderPayPlatform === 5"><el-tag type="danger">小程序</el-tag></span>
          <span v-if="scope.row.orderPayPlatform === 6"><el-tag type="success">后台导入</el-tag></span>
        </template>
      </el-table-column>
      <el-table-column prop="orderApp" label="订单来源" width="120" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.orderApp === 1"><el-tag type="success">app</el-tag></span>
          <span v-if="scope.row.orderApp === 2"><el-tag type="primary">标讯</el-tag></span>
          <span v-if="scope.row.orderApp === 3"><el-tag type="warning">pc</el-tag></span>
          <span v-if="scope.row.orderApp === 4"><el-tag type="warning">微信</el-tag></span>
          <span v-if="scope.row.orderApp === 5"><el-tag type="warning">小程序</el-tag></span>
          <span v-if="scope.row.orderApp === 6"><el-tag type="warning">后台</el-tag></span>
        </template>
      </el-table-column>
      <el-table-column prop="isInvoice" label="是否开发票" width="100" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.isInvoice === 0"><el-tag type="info">未申请</el-tag></span>
          <span v-if="scope.row.isInvoice === 1"><el-tag type="warning">已申请</el-tag></span>
        </template>
      </el-table-column>
      <el-table-column prop="invoiceStatus" label="开票进度" width="100" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.invoiceStatus === 0"><el-tag type="danger">未开票</el-tag></span>
          <span v-if="scope.row.invoiceStatus === 1"><el-tag type="warning">开票中</el-tag></span>
          <span v-if="scope.row.invoiceStatus === 2"><el-tag type="primary">开票完成</el-tag></span>
        </template>
      </el-table-column>
      <el-table-column prop="orderCreateTime" label="下单时间" width="160" align="center"/>
      <el-table-column prop="orderPayTime" label="支付时间" width="160" align="center"/>
      <el-table-column fixed="right" label="操作" width="120" align="center">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="handleOpenMakeInvoicePanel(scope)">开发票</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页器-->
    <el-pagination
      layout="total, sizes, prev, pager, next, jumper"
      :current-page="form.pageNum"
      :page-size="form.pageSize"
      :total="form.total"
      :page-sizes="[12, 50, 100, 200]"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange">
    </el-pagination>
    <!-- 开具发票 -->
    <el-dialog title="发票申请" :visible.sync="pageData.makeInvoiceStatus" size="tiny" width="960px" :before-close="handleCloseMakeInvoicePanel">
      <div><span>相关订单号：</span><el-tag v-for="item in responseData.invoiceOrderList" :key="item">{{item}}</el-tag></div>
      <div class="data-table" style="margin-top: 20px">
        <el-table :data="responseData.invoiceList"
                  border style="width: 100%;"
                  element-loading-text="拼命加载中"
                  element-loading-spinner="el-icon-loading"
                  element-loading-background="rgba(0, 0, 0, 0.8)"
                  :header-cell-style="{ background: '#545C64', color: '#ffffff' }">
          <el-table-column fixed="left" prop="invoiceId" label="发票编号" width="180" align="center"/>
          <el-table-column prop="invoicePayee" label="收款单位" width="280" align="center"/>
          <el-table-column prop="invoiceTitle" label="发票抬头" width="280" align="center"/>
          <el-table-column prop="invoiceType" label="发票类型" width="80" align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.invoiceType === 1"><el-tag type="primary">单位</el-tag></span>
              <span v-if="scope.row.invoiceType === 2"><el-tag type="success">个人</el-tag></span>
            </template>
          </el-table-column>
          <el-table-column prop="invoiceDutyParagraph" label="发票税号" width="180" align="center"/>
          <el-table-column prop="invoiceContent" label="发票内容" width="120" align="center"/>
          <el-table-column prop="invoiceMoney" label="发票金额" width="120" align="center"/>
          <el-table-column prop="invoiceRemark" label="备注说明" width="240" align="center"/>
          <el-table-column prop="invoiceAddressPhone" label="地址电话" width="240" align="center"/>
          <el-table-column prop="invoiceBankAccount" label="开户行账号" width="240" align="center"/>
          <el-table-column prop="invoiceRecipients" label="收件人" width="80" align="center"/>
          <el-table-column prop="invoicePhone" label="联系电话" width="120" align="center"/>
          <el-table-column prop="invoiceDetailedAddress" label="详细地址" width="240" align="center"/>
          <el-table-column prop="invoiceEmail" label="电子邮箱" width="240" align="center"/>
          <el-table-column prop="invoiceCreateTime" label="申请时间" width="120" align="center"/>
        </el-table>
        <!--进度步骤-->
        <el-card class="card">
          <div class="clearfix" style="margin-left: auto">
            <el-steps :active="pageData.makeInvoice.invoiceMakeOutStatus" finish-status="success">
              <el-step title="未开"></el-step>
              <el-step title="开票中"></el-step>
              <el-step title="邮递完成"></el-step>
            </el-steps>
            <div style="margin-top: 20px">
              {{pageData.makeInvoice.invoiceMakeOutStatus}}
              <el-form :model="form.invoiceExpressInfo" label-width="80px" ref="form.invoiceExpressInfo" v-if="pageData.makeInvoice.invoiceMakeOutStatus === 1">
                <el-form-item prop="invoiceNumber" label="发票号">
                  <el-input placeholder="请输入发票编号" v-model="form.invoiceExpressInfo.invoiceNumber" class="filter-item" auto-complete="off"/>
                </el-form-item>
                <el-form-item prop="expressNumber" label="快递单号">
                  <el-input placeholder="请输入快递单号" v-model="form.invoiceExpressInfo.expressNumber" class="filter-item" auto-complete="off"/>
                </el-form-item>
                <el-form-item prop="expressCompany" label="快递公司">
                  <el-input placeholder="请输入快递公司名称" v-model="form.invoiceExpressInfo.expressCompany" class="filter-item" auto-complete="off"/>
                </el-form-item>
              </el-form>
            </div>
            <el-button style="margin-top: 12px;" @click="handleOpenMakeOutInvoiceButtonClick">
              <span v-if="pageData.makeInvoice.invoiceMakeOutStatus === 0">开发票</span>
              <span v-if="pageData.makeInvoice.invoiceMakeOutStatus === 1">邮递发票</span>
            </el-button>
          </div>
        </el-card>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  // 组件引入
  import XLSX from 'xlsx';
  // 方法工具引入
  import { PermissionsToDetectFormUser } from '@/utils/PermissionsDetect';
  import { getPermission } from '@/utils/UserCookies';
  // 接口引入
  import { loadCmsOrderList,loadCmsOrderExpertList,loadCmsOrderInvoiceExpertList,loadCmsOrderInvoiceList,updateCmsOrderInvoiceExpressInfoData,updateCmsOrderInvoiceStatus } from "@/api/operation";
  export default {
    name: "order",
    //import引入的组件需要注入到对象中才能使用
    components: {},
    data() {
      return {
        pageData:{
          searchSourceList: [
            {label: "订单来源", value: -1},
            {label: "易采通APP", value: 1},
            {label: "易找标PC", value: 2},
            {label: "PC", value: 3}
          ],
          searchPlateList: [
            {label: "支付来源", value: -1},
            {label: "易采通IOS", value: 1},
            {label: "易采通Android", value: 2},
            {label: "易找标PC", value: 3}
          ],
          searchPayTypeList: [
            {label: "支付方式", value: -1},
            {label: "微信支付", value: 1},
            {label: "支付宝支付", value: 2},
            {label: "转账支付", value: 3},
            {label: "余额支付", value: 4},
            {label: "IOS内购", value: 5},
            {label: "微信扫码", value: 6},
            {label: "微信jsapi", value: 7},
            {label: "支付宝扫码", value: 8}
          ],
          searchPayStatusList: [
            {label: "支付状态", value: -1},
            {label: "未支付", value: 0},
            {label: "已支付", value: 1},
            {label: "失效订单", value: 2}
          ],
          searchInvoiceStatusList: [
            {label: "发票状态", value: -1},
            {label: "未开票/不开票", value: 0},
            {label: "申请开票(未开票)", value: 1},
            {label: "开票中", value: 2},
            {label: "开票完成", value: 3}
          ],
          searchCommodityTypeList: [
            {label: "商品类型", value: -1},
            {label: "VIP", value: 1},
            {label: "采币", value: 2},
            {label: "内容", value: 3},
            {label: "问题", value: 4},
            {label: "回答", value: 5},
            {label: "研修班", value: 6}
          ],
          unlinkPanels: true,
          pickerOptions: {
            shortcuts: [{
              text: '最近一周',
              onClick(picker) {
                const end = new Date();
                const start = new Date();
                start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                picker.$emit('pick', [start, end]);
              }
            }, {
              text: '最近一个月',
              onClick(picker) {
                const end = new Date();
                const start = new Date();
                start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                picker.$emit('pick', [start, end]);
              }
            }, {
              text: '最近三个月',
              onClick(picker) {
                const end = new Date();
                const start = new Date();
                start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                picker.$emit('pick', [start, end]);
              }
            }]
          },
          loading: false,
          makeInvoiceStatus: false,
          makeInvoice: {}
        },// 页面配置数据
        form:{
          searchSource: -1,
          searchPlate: -1,
          searchPayType: -1,
          searchPayStatus: -1,
          searchInvoiceStatus: -1,
          searchCommodityType: -1,
          searchDate: "",
          startDate: "",
          endDate: "",
          pageNum: 1,
          pageSize: 12,
          total: 0,
          selection: [],
          invoiceExpressInfo:{
            invoiceNumber: "",
            expressNumber: "",
            expressCompany: ""
          }
        },// 页面表单
        formRules: {},// 表单验证
        responseData: {
          tableList: [],
          expertOrderList: [],
          expertOrderInvoiceList: [],
          invoiceList: [],
          invoiceOrderList: []
        },// 接口响应数据
      }
    },
    //监听属性 类似于data概念
    computed: {},
    //监控data中的数据变化
    watch: {},
    //方法集合
    methods:{
      // 事件函数
      handlePageInit(){
        this.pageData.loading = true;// 创建加载窗口
        this.loadCmsOrderList();// 读取路由角色列表
      },// 页面初始化事件
      handleCurrentChange(val){
        this.form.pageNum = val;// 更换页码
        this.handlePageInit();// 进行数据加载
      },// 页码切换事件
      handleSizeChange(val){
        this.form.pageSize = val;// 更换页面大小
        this.handlePageInit();// 进行数据加载
      },// 页面size切换事件
      handleTableSelection(val){
        let list = [];// 初始化多选数组
        for (let i=0; i<val.length; i++){
          list.push(val[i].orderId);
        }// 遍历多选的列表，将ID拼入数组中
        this.form.selection = list;// 进行多选值的切换
      },// 表格多选事件
      handleExportOrderButtonClick(){
        if (PermissionsToDetectFormUser(getPermission(), "580006")){
          this.$confirm('是否确定导出当前筛选结果的订单数据?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.pageData.loading = true;
            this.loadCmsOrderExpertList();
          }).catch(close => {
            console.log(close);
            this.$message.info("已取消操作");
          });
        } else {
          this.$message.warning('您的权限不足，无法使用此功能，请联系管理员');
        }
      },// 导出订单
      handleExportOrderInvoiceButtonClick(){
        if (PermissionsToDetectFormUser(getPermission(), "580007")){
          this.$confirm('是否确定导出当前筛选结果的发票数据?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.pageData.loading = true;
            this.loadCmsOrderInvoiceExpertList();
          }).catch(close => {
            console.log(close);
            this.$message.info("已取消操作");
          });
        } else {
          this.$message.warning('您的权限不足，无法使用此功能，请联系管理员');
        }
      },// 发票导出
      handleOpenMakeInvoicePanel(scope){
        if (PermissionsToDetectFormUser(getPermission(), "580008")) {
          if (scope.row.isInvoice === 1 && scope.row.invoiceStatus !== 2){
            let prams = {orderId: scope.row.orderId};
            this.loadCmsOrderInvoiceList(prams);
          } else {
            this.$message.info('当前订单无可操作发票');
          }
        } else {
          this.$message.warning('您的权限不足，无法使用此功能，请联系管理员');
        }
      },// 打开开发票面板
      handleCloseMakeInvoicePanel(){
        this.$confirm("确认关闭？").then(response => {
          this.pageData.makeInvoiceStatus = false;
          this.responseData.invoiceList = [];
          this.pageData.makeInvoice = {};
          this.responseData.invoiceOrderList = [];
        }).catch(err => {
          console.log(err);
        });
      },// 关闭开发票面板
      handleOpenMakeOutInvoiceButtonClick(){
        if (PermissionsToDetectFormUser(getPermission(), "580008")) {
          this.$confirm('是否修改发票开放状态, 请核对后继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            let param = {
              invoiceId: this.pageData.makeInvoice.invoiceId,
              invoiceNumber: this.form.invoiceExpressInfo.invoiceNumber,
              expressNumber: this.form.invoiceExpressInfo.expressNumber,
              expressCompany: this.form.invoiceExpressInfo.expressCompany
            };
            this.updateCmsOrderInvoiceExpressInfoData(param);
          }).catch(close => {
            console.log(close);
            this.$message.info("已取消操作");
          });
        } else {
          this.$message.warning('您的权限不足，无法使用此功能，请联系管理员');
        }
      },// 开发票按钮点击事件
      // 接口
      loadCmsOrderList(){
        if (this.form.searchDate !== null && this.form.searchDate !== ""){
          let startData = new Date(this.form.searchDate[0]);
          startData = startData.getFullYear()+"-"+("0"+(startData.getMonth()+1)).slice(-2)+"-"+startData.getDate();
          let endData = new Date(this.form.searchDate[1]);
          endData = endData.getFullYear()+"-"+("0"+(endData.getMonth()+1)).slice(-2)+"-"+endData.getDate();
          this.form.startDate = startData + " 00:00:00";
          this.form.endDate = endData + " 23:59:59";
        }
        loadCmsOrderList(this.form).then(response => {
          if (response.code === "200"){
            this.pageData.loading = false;
            this.responseData.tableList = response.data.list;
            this.form.total = response.data.total;
          } else {
            this.$message.warning(response.message);
          }
        }).catch( error =>{
          console.log(error);
          this.$message.error(error);
        })
      },// 获取订单列表
      loadCmsOrderExpertList(){
        if (this.form.searchDate !== null && this.form.searchDate !== ""){
          let startData = new Date(this.form.searchDate[0]);
          startData = startData.getFullYear()+"-"+("0"+(startData.getMonth()+1)).slice(-2)+"-"+startData.getDate();
          let endData = new Date(this.form.searchDate[1]);
          endData = endData.getFullYear()+"-"+("0"+(endData.getMonth()+1)).slice(-2)+"-"+endData.getDate();
          this.form.startDate = startData + " 00:00:00";
          this.form.endDate = endData + " 23:59:59";
        }
        loadCmsOrderExpertList(this.form).then(response => {
          if (response.code === "200"){
            this.responseData.expertOrderList = response.data;
            // 导出数据统计表格
            let dataList = [];
            dataList.push(["购买用户手机号", "购买用户昵称", "购买金额", "购买物品", "内容版块", "细分频道", "支付方式", "支付平台", "是否索要发票", "开票状态", "下单时间", "到账时间"]);
            for (let i=0; i<this.responseData.expertOrderList.length; i++){
              let data = [];
              data.push(this.responseData.expertOrderList[i].userPhone);
              data.push(this.responseData.expertOrderList[i].userName);
              data.push(this.responseData.expertOrderList[i].amountOfPurchase);
              data.push(this.responseData.expertOrderList[i].purchaseItems);
              data.push(this.responseData.expertOrderList[i].classType);
              data.push(this.responseData.expertOrderList[i].nicheChannel);
              data.push(this.responseData.expertOrderList[i].payType);
              data.push(this.responseData.expertOrderList[i].payPlat);
              data.push(this.responseData.expertOrderList[i].isInvoice);
              data.push(this.responseData.expertOrderList[i].invoiceStatus);
              data.push(this.responseData.expertOrderList[i].orderCreateTime);
              data.push(this.responseData.expertOrderList[i].orderPayTime);
              dataList.push(data);
            }
            this.pageData.loading = false;
            setTimeout(function () {
              const ws = XLSX.utils.aoa_to_sheet(dataList);
              const wb = XLSX.utils.book_new();
              XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
              XLSX.writeFile(wb, "订单导出数据.xlsx");
            }, 800);
            this.handlePageInit();
          } else {
            this.$message.warning(response.message);
          }
        }).catch( error =>{
          console.log(error);
          this.$message.error(error);
        })
      },// 导出订单列表
      loadCmsOrderInvoiceExpertList(){
        if (this.form.searchDate !== null && this.form.searchDate !== ""){
          let startData = new Date(this.form.searchDate[0]);
          startData = startData.getFullYear()+"-"+("0"+(startData.getMonth()+1)).slice(-2)+"-"+startData.getDate();
          let endData = new Date(this.form.searchDate[1]);
          endData = endData.getFullYear()+"-"+("0"+(endData.getMonth()+1)).slice(-2)+"-"+endData.getDate();
          this.form.startDate = startData + " 00:00:00";
          this.form.endDate = endData + " 23:59:59";
        }
        loadCmsOrderInvoiceExpertList(this.form).then(response => {
          if (response.code === "200"){
            this.responseData.expertOrderInvoiceList = response.data;
            // 导出数据统计表格
            let dataList = [];
            dataList.push(["ID", "订单编号", "支付方式", "发票抬头", "税号", "发票内容", "购买内容", "开票金额",  "开票申请时间", "电子邮箱", "备注"]);
            for (let i=0; i<this.responseData.expertOrderInvoiceList.length; i++){
              let data = [];
              data.push(this.responseData.expertOrderInvoiceList[i].id);
              data.push(this.responseData.expertOrderInvoiceList[i].orderId);
              data.push(this.responseData.expertOrderInvoiceList[i].orderPayType);
              data.push(this.responseData.expertOrderInvoiceList[i].invoiceTitle);
              data.push(this.responseData.expertOrderInvoiceList[i].invoiceDutyParagraph);
              data.push(this.responseData.expertOrderInvoiceList[i].invoiceContent);
              data.push(this.responseData.expertOrderInvoiceList[i].orderDescribe);
              data.push(this.responseData.expertOrderInvoiceList[i].invoiceMoney);
              data.push(this.responseData.expertOrderInvoiceList[i].invoiceCreateTime);
              data.push(this.responseData.expertOrderInvoiceList[i].invoiceEmail);
              data.push(this.responseData.expertOrderInvoiceList[i].invoiceRemark);
              dataList.push(data);
            }
            this.pageData.loading = false;
            setTimeout(function () {
              const ws = XLSX.utils.aoa_to_sheet(dataList);
              const wb = XLSX.utils.book_new();
              XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
              XLSX.writeFile(wb, "发票导出数据.xlsx");
            }, 800);
            this.handlePageInit();
          } else {
            this.$message.warning(response.message);
          }
        }).catch( error =>{
          console.log(error);
          this.$message.error(error);
        })
      },// 导出发票列表
      loadCmsOrderInvoiceList(param){
        loadCmsOrderInvoiceList(param).then(response => {
          if (response.code === "200"){
            this.pageData.makeInvoiceStatus = true;
            this.responseData.invoiceList = response.data.list;
            this.pageData.makeInvoice.invoiceId = this.responseData.invoiceList[0].invoiceId;
            this.pageData.makeInvoice.invoiceMakeOutStatus = this.responseData.invoiceList[0].invoiceMakeOutStatus;
            this.responseData.invoiceOrderList = response.data.invoiceOrderList;
          } else {
            this.$message.warning(response.message);
          }
        }).catch(error => {
          console.log(error);
          this.$message.error(error);
        })
      },// 获取订单发票信息所关联的数据
      updateCmsOrderInvoiceExpressInfoData(param){
        updateCmsOrderInvoiceExpressInfoData(param).then(response => {
          if (response.code === "200"){
            let param = {
              invoiceId: this.pageData.makeInvoice.invoiceId,
              invoiceMakeOutStatus: this.pageData.makeInvoice.invoiceMakeOutStatus
            };
            this.updateCmsOrderInvoiceStatus(param);
          } else {
            this.$message.warning(response.message);
          }
        }).catch(error => {
          console.log(error);
          this.$message.error(error);
        })
      },// 保存发票邮寄信息
      updateCmsOrderInvoiceStatus(param){
        updateCmsOrderInvoiceStatus(param).then(response => {
          if (response.code === "200"){
            this.$message.success('发票进度更新成功');
            this.pageData.makeInvoiceStatus = false;
            this.handlePageInit();
          } else {
            this.$message.warning(response.message);
          }
        }).catch(error => {
          console.log(error);
          this.$message.error(error);
        })
      },// 更新开票状态
    },
    //生命周期 - 创建完成（可以访问当前this实例）
    created: function () {
      let _this = this;
      setTimeout(function () {
        _this.handlePageInit();
      }, 800);
    },
    //生命周期 - 挂载完成（可以访问DOM元素）
    mounted() {},
    beforeCreate() {}, //生命周期 - 创建之前
    beforeMount() {}, //生命周期 - 挂载之前
    beforeUpdate() {}, //生命周期 - 更新之前
    updated() {}, //生命周期 - 更新之后
    beforeDestroy() {}, //生命周期 - 销毁之前
    destroyed() {}, //生命周期 - 销毁完成
    activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
  };
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
</style>
